import 'dart:async';

import 'package:afmjb1/a_view.dart';
import 'package:afmjb1/mjb/custom_webview.dart';
import 'package:afmjb1/mjb/log_utls.dart';
import 'package:afmjb1/mjb/net_util.dart';
import 'package:afmjb1/mjb/utils.dart';
import 'package:flutter/material.dart';

class SplashScreenPage extends StatefulWidget {
  const SplashScreenPage({super.key});

  @override
  State<SplashScreenPage> createState() => _SplashScreenPageState();
}

Future<Map?> getSplashResp() async {
  Map? res = await TMWHttps.instance.get("/com.kgnyzw.qpoqgjq");
  return res;
}

class _SplashScreenPageState extends State<SplashScreenPage> {
  @override
  void initState() {
    super.initState();
    printLog("initState getSplashResp...");

    getSplashResp().then((map) {
      if (map != null) {
        if (map["url"] != null && (map["url"] as String).isNotEmpty) {
          Utils.mHttpUrl = map["url"] as String;

          Utils.mAppsflyerKey = map["key"] as String;

          var jump = map["jump"] as int;

          printLog("mHttpUrl=${Utils.mHttpUrl}");

          printLog("mAppsflyerKey=${Utils.mAppsflyerKey}");

          printLog("jump=$jump");

          if (jump == 1) {
            Navigator.pushReplacement(context,
                MaterialPageRoute(builder: (context) => const BWeb()));
          } else {
            Navigator.pushReplacement(
                context, MaterialPageRoute(builder: (context) => ADemo()));
          }
        } else {
          Navigator.pushReplacement(
              context, MaterialPageRoute(builder: (context) => const ADemo()));
        }
      } else {
        //A_View
        Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context) => const ADemo()));
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
        color: cffffff,
        child: Image.asset("assets/splash/img.png", fit: BoxFit.cover));
  }
}
